package com.coffee.admin.controller.platform;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.coffee.admin.api.common.query.GtRegionQuery;
import com.coffee.admin.api.common.result.GtRegionResult;
import com.coffee.admin.api.common.service.GtRegionService;
import com.coffee.admin.api.platform.query.CarouselFigureQuery;
import com.coffee.admin.api.platform.query.PlatformBaseDeployQuery;
import com.coffee.admin.api.platform.query.PlatformSystemDeployQuery;
import com.coffee.admin.api.platform.query.RechargeQuery;
import com.coffee.admin.api.platform.rep.PlatformBaseDeployListRep;
import com.coffee.admin.api.platform.req.*;
import com.coffee.admin.api.platform.result.CarouselFigureResult;
import com.coffee.admin.api.platform.result.PlatformSystemDeployResult;
import com.coffee.admin.api.platform.result.RechargeRuleResult;
import com.coffee.admin.api.platform.service.CarouselFigureService;
import com.coffee.admin.api.platform.service.PlatformBaseDeployService;
import com.coffee.admin.api.platform.service.PlatformSystemDeployService;
import com.coffee.admin.api.platform.service.RechargeRuleService;
import com.coffee.admin.controller.BaseController;
import com.coffee.core.anotation.OperLog;
import com.coffee.core.anotation.PlatformLoginCheck;
import com.coffee.core.anotation.SupplierLoginCheck;
import com.coffee.core.entity.Page;
import com.coffee.core.entity.PagerInfo;
import com.coffee.core.enums.ExceptionEnum;
import com.coffee.core.exception.BusinessException;
import com.coffee.core.result.Result;
import com.coffee.core.util.BeanUtilExt;
import com.coffee.core.util.BeanUtils;
import com.coffee.core.util.DTOUtils;
import com.coffee.order.api.sku.query.UrbanFullReductionQuery;
import com.coffee.order.api.sku.result.UrbanFullReductionResult;
import com.coffee.order.api.sku.service.UrbanFullReductionService;
import com.coffee.sku.api.sku.query.SkuCategoryAttributeQuery;
import com.coffee.sku.api.sku.query.SkuCategoryQuery;
import com.coffee.sku.api.sku.req.AddSkuCategoryAttributeReq;
import com.coffee.sku.api.sku.req.SkuCategoryReq;
import com.coffee.sku.api.sku.result.SkuCategoryAttributeDetailResult;
import com.coffee.sku.api.sku.result.SkuCategoryResult;
import com.coffee.sku.api.sku.service.SkuCategoryAttributeService;
import com.coffee.sku.api.sku.service.SkuCategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/platform")
public class PlatformSystemController extends BaseController {

    @DubboReference
    private PlatformSystemDeployService platformSystemDeployService;
    @DubboReference
    private PlatformBaseDeployService platformBaseDeployService;
    @DubboReference
    private CarouselFigureService carouselFigureService;
    @DubboReference
    private SkuCategoryService skuCategoryService;
    @DubboReference
    private SkuCategoryAttributeService skuCategoryAttributeService;
    @DubboReference
    private UrbanFullReductionService urbanFullReductionService;
    @DubboReference
    private GtRegionService gtRegionService;
    @DubboReference
    private RechargeRuleService rechargeRuleService;

    @OperLog(operModul = "平台-系统管理", operDesc = "查询系统设置列表")
    @PlatformLoginCheck(alias = "SystemManageListAlias")
    @PostMapping(value = "/system/list")
    public Result<Page<PlatformSystemDeployResult>> platformSystemDeployList(@RequestBody PlatformSystemDeployReq req, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(req.getPageSize(), req.getPageIndex());
        PlatformSystemDeployQuery query = new PlatformSystemDeployQuery();
        Page<PlatformSystemDeployResult> platformSystemDeployResultPage = platformSystemDeployService.getPager(query, pagerInfo);
        return Result.success(platformSystemDeployResultPage);
    }


    @OperLog(operModul = "平台-系统管理", operDesc = "修改系统设置")
    @PlatformLoginCheck(alias = "SystemManageOperationAlias")
    @PostMapping(value = "/system/update")
    public Result<String> updateSystem(@RequestBody PlatformSystemDeployUpdateReq req, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        PlatformSystemDeployResult result = new PlatformSystemDeployResult();
        BeanUtils.copyProperties(result, req);
        result.setRoleType("platform");
        platformSystemDeployService.addOrUpdate(result);
        return Result.success("SUCCESS");
    }


    @OperLog(operModul = "平台-基础设置", operDesc = "查询基础设置列表")
    @PlatformLoginCheck(alias = "BaseManageListAlias")
    @PostMapping(value = "/base/list")
    public Result<Page<PlatformBaseDeployListRep>> baseList(@RequestBody PlatformBaseDeployReq platformBaseDeployReq, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(platformBaseDeployReq.getPageSize(), platformBaseDeployReq.getPageIndex());
        PlatformBaseDeployQuery param = new PlatformBaseDeployQuery();
        param.setName(platformBaseDeployReq.getName());
        param.setPid(0);
        Page<PlatformBaseDeployListRep> pager = platformBaseDeployService.getPager(param, pagerInfo);
        return Result.success(pager);
    }


    @OperLog(operModul = "平台-基础设置-添加", operDesc = "添加基础设置")
    @PlatformLoginCheck(alias = "BaseManageOperationAlias")
    @PostMapping(value = "/base/add")
    public Result<String> baseAdd(@RequestBody PlatformBaseDeployAddReq platformBaseDeployAddReq, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        platformBaseDeployService.add(platformBaseDeployAddReq);
        return Result.success("SUCCESS");
    }

    @OperLog(operModul = "平台-基础设置-修改", operDesc = "修改基础设置")
    @PlatformLoginCheck(alias = "BaseManageOperationAlias")
    @PostMapping(value = "/base/update")
    public Result<String> baseUpdate(@RequestBody PlatformBaseDeployUpdateReq platformBaseDeployUpdateReq, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        platformBaseDeployService.update(platformBaseDeployUpdateReq);
        return Result.success("SUCCESS");
    }

    @OperLog(operModul = "平台-基础设置-删除", operDesc = "删除基础设置")
    @PlatformLoginCheck(alias = "BaseManageOperationAlias")
    @PostMapping(value = "/base/delete")
    public Result<String> baseUpdate(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) {
        Integer id = json.getInteger("id");
        platformBaseDeployService.delete(id);
        return Result.success("SUCCESS");
    }


    @OperLog(operModul = "平台-轮播图设置", operDesc = "查看轮播图列表")
    @PlatformLoginCheck(alias = "CarouselFigureListAlias")
    @PostMapping(value = "/carouselFigure/list")
    public Result<Page<CarouselFigureResult>> carouselFigureList(@RequestBody CarouselFigureReq carouselFigureReq, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(carouselFigureReq.getPageSize(), carouselFigureReq.getPageIndex());
        Page<CarouselFigureResult> pager = carouselFigureService.getPager(new CarouselFigureQuery(), pagerInfo);
        return Result.success(pager);
    }


    @OperLog(operModul = "平台-轮播图设置", operDesc = "查看轮播图启用列表")
    @PlatformLoginCheck(alias = "CarouselFigureListAlias")
    @PostMapping(value = "/carouselFigure/enable/list")
    public Result<List<CarouselFigureResult>> carouselFigureList(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonObject) {
        Integer cityId = jsonObject.getInteger("cityId");
        PagerInfo pagerInfo = setDefaultPageInfo(5, 0);
        CarouselFigureQuery carouselFigureQuery = new CarouselFigureQuery();
        carouselFigureQuery.setCityId(cityId);
        Page<CarouselFigureResult> pager = carouselFigureService.getPager(carouselFigureQuery, pagerInfo);
        return Result.success(pager.getData());
    }


    @OperLog(operModul = "平台-轮播图设置-新建轮播图", operDesc = "新建轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/add")
    public Result<String> carouselAdd(@RequestBody CarouselFigureReq req, HttpServletRequest request, HttpServletResponse response) {
        CarouselFigureResult carouselFigureResult = new CarouselFigureResult();
        BeanUtilExt.copyProperties(carouselFigureResult, req);
        try {
            carouselFigureService.addOrUpdate(carouselFigureResult);
            return Result.success("success");
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
    }

    @OperLog(operModul = "平台-轮播图设置-编辑轮播图", operDesc = "编辑轮播图轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/update")
    public Result<String> carouselUpdate(@RequestBody CarouselFigureReq req, HttpServletRequest request, HttpServletResponse response) {
        CarouselFigureResult carouselFigureResult = new CarouselFigureResult();
        BeanUtils.copyProperties(carouselFigureResult, req);
        try {
            carouselFigureService.addOrUpdate(carouselFigureResult);
            return Result.success("success");
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
    }


    @OperLog(operModul = "平台-轮播图设置-上下架轮播图", operDesc = "上下轮播图轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/isEnable")
    public Result<String> carouselEnable(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonObject) {
        String ids = jsonObject.getString("ids");
        try {
            carouselFigureService.carouselEnable(ids);
            return Result.success("success");
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
    }

    @OperLog(operModul = "平台-轮播图设置-删除轮播图", operDesc = "删除轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/delete")
    public Result<String> carouselDelete(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonObject) {
        Integer id = jsonObject.getInteger("id");
        carouselFigureService.delete(id);
        return Result.success("success");
    }


    @OperLog(operModul = "平台-轮播图设置-删除轮播图", operDesc = "删除轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/city/add")
    public Result<String> carouselCityAdd(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonObject) throws BusinessException {
        JSONArray idJSONArray = jsonObject.getJSONArray("ids");
        List<Integer> ids = JSONObject.parseArray(idJSONArray.toJSONString(), Integer.class);
        Integer cityId = jsonObject.getInteger("cityId");
        carouselFigureService.addCarouselFigureCity(ids, cityId);
        return Result.success("success");
    }

    @OperLog(operModul = "平台-轮播图设置-删除轮播图", operDesc = "删除轮播图")
    @PlatformLoginCheck(alias = "CarouselFigureOperationAlias")
    @PostMapping(value = "/carouselFigure/city/delete")
    public Result<String> carouselCityDelete(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonObject) throws BusinessException {
        Integer cityId = jsonObject.getInteger("cityId");
        Integer id = jsonObject.getInteger("id");
        carouselFigureService.deleteCarouselFigureCity(id, cityId);
        return Result.success("success");
    }


    @OperLog(operModul = "平台-类目管理", operDesc = "分页查看类目列表")
    @PlatformLoginCheck(alias = "SkuCategoryListAlias")
    @PostMapping(value = "/category/list")
    public Result<Page<SkuCategoryResult>> skuCategoryList(@RequestBody SkuCategoryReq req, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(req.getPageSize(), req.getPageIndex());
        SkuCategoryQuery param = new SkuCategoryQuery();
        BeanUtilExt.copyProperties(param, req);
        param.setPid(0);
        Page<SkuCategoryResult> pager = skuCategoryService.getPager(param, pagerInfo);
        return Result.success(pager);
    }


    @OperLog(operModul = "平台-类目管理", operDesc = "查看类目列表")
    @PlatformLoginCheck(alias = "SkuCategoryListAlias")
    @PostMapping(value = "/category/all/list")
    public Result<List<SkuCategoryResult>> skuCategoryAllList(HttpServletRequest request, HttpServletResponse response) {
        List<SkuCategoryResult> list = skuCategoryService.getList("N");
        return Result.success(list);
    }


    @OperLog(operModul = "平台-类目管理", operDesc = "查看类目列表")
    @PlatformLoginCheck(alias = "SkuCategoryListAlias")
    @PostMapping(value = "/category/sort/update")
    public Result<String> skuCategorySortUpdate(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        JSONArray id = jsonObject.getJSONArray("ids");
        List<Integer> integers = JSONObject.parseArray(JSONObject.toJSONString(id), Integer.class);
        try {
            if (integers.size() <= 0) {
                throw BusinessException.build(ExceptionEnum.ERROR_1317);
            }
            skuCategoryService.updateFirstSort(integers);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }

    @OperLog(operModul = "平台-类目管理", operDesc = "查看类目列表")
    @PlatformLoginCheck(alias = "SkuCategoryListAlias")
    @PostMapping(value = "/category/first/list")
    public Result<List<SkuCategoryResult>> skuCategoryfirstList(HttpServletRequest request, HttpServletResponse response) {
        List<SkuCategoryResult> list = skuCategoryService.getList("Y");
        return Result.success(list);
    }


    @OperLog(operModul = "平台-类目管理-编辑类目", operDesc = "编辑类目")
    @PlatformLoginCheck(alias = "SkuCategoryOperationAlias")
    @PostMapping(value = "/category/update")
    public Result<String> carouselUpdate(@RequestBody List<SkuCategoryReq> skuCategoryReqs, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        List<SkuCategoryResult> skuCategoryResults = DTOUtils.convertList(skuCategoryReqs, SkuCategoryResult.class);
        skuCategoryService.update(skuCategoryResults);
        return Result.success("success");
    }

    @OperLog(operModul = "平台-类目管理-添加类目", operDesc = "添加类目")
    @PlatformLoginCheck(alias = "SkuCategoryOperationAlias")
    @PostMapping(value = "/category/add")
    public Result<String> carouselAdd(@RequestBody SkuCategoryReq req, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        SkuCategoryResult param = new SkuCategoryResult();
        BeanUtils.copyProperties(param, req);
        skuCategoryService.add(param);
        return Result.success("success");
    }

    @OperLog(operModul = "平台-类目管理-删除类目", operDesc = "删除类目")
    @PlatformLoginCheck(alias = "SkuCategoryOperationAlias")
    @PostMapping(value = "/category/delete")
    public Result<String> delete(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        Integer id = jsonObject.getInteger("id");
        try {
            skuCategoryService.delete(id);
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }


    @OperLog(operModul = "平台-类目属性管理", operDesc = "类目属性添加")
    @PlatformLoginCheck(alias = "CategoryAttributeOperationAlias")
    @PostMapping(value = "/category/attribute/add")
    public Result<String> skuCategoryAttributeAdd(@RequestBody AddSkuCategoryAttributeReq req, HttpServletRequest request, HttpServletResponse response) {
        try {
            skuCategoryAttributeService.add(req);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }

    @OperLog(operModul = "平台-类目属性管理", operDesc = "类目属性修改")
    @PlatformLoginCheck(alias = "CategoryAttributeOperationAlias")
    @PostMapping(value = "/category/attribute/update")
    public Result<String> skuCategoryAttributeUpdate(@RequestBody AddSkuCategoryAttributeReq req, HttpServletRequest request, HttpServletResponse response) {
        try {
            skuCategoryAttributeService.update(req);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }

    @OperLog(operModul = "平台-类目属性管理", operDesc = "类目属性删除")
    @PlatformLoginCheck(alias = "CategoryAttributeOperationAlias")
    @PostMapping(value = "/category/attribute/delete")
    public Result<String> skuCategoryAttributeDelete(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        Integer id = jsonObject.getInteger("id");
        skuCategoryAttributeService.deleteByCategory(id);
        return Result.success("success");
    }


    @OperLog(operModul = "平台-类目属性管理", operDesc = "类目属性列表")
    @PlatformLoginCheck(alias = "CategoryAttributeListAlias")
    @PostMapping(value = "/category/attribute/list")
    public Result<Page<SkuCategoryAttributeDetailResult>> skuCategoryAttributeList(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        Integer pageSize = jsonObject.getInteger("pageSize");
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        PagerInfo pagerInfo = setDefaultPageInfo(pageSize, pageIndex);
        Page<SkuCategoryAttributeDetailResult> pager = skuCategoryAttributeService.getPager(new SkuCategoryAttributeQuery(), pagerInfo);
        return Result.success(pager);
    }

    @OperLog(operModul = "平台-类目属性管理", operDesc = "类目属性详情")
    @PlatformLoginCheck(alias = "CategoryAttributeListAlias")
    @PostMapping(value = "/category/attribute/detail")
    public Result<SkuCategoryAttributeDetailResult> skuCategoryAttributeDetail(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        Integer categoryId = jsonObject.getInteger("categoryId");
        if (categoryId == null) {
            return Result.failed(ExceptionEnum.ERROR_1317);
        }
        SkuCategoryAttributeDetailResult detailByCategoryId = skuCategoryAttributeService.getDetailByCategoryId(categoryId);
        return Result.success(detailByCategoryId);
    }

    @OperLog(operModul = "供应商-系统管理", operDesc = "查询满减规则设置")
    @PlatformLoginCheck(alias = "SystemManageListAlias")
    @PostMapping(value = "/urbanFullReduction/list")
    public Result<Page<UrbanFullReductionResult>> urbanFullReductionList(@RequestBody PlatformSystemDeployReq req, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(req.getPageSize(), req.getPageIndex());
        UrbanFullReductionQuery query = new UrbanFullReductionQuery();
        query.setSupplierId(getSupplier().getSupplierId());
        Page<UrbanFullReductionResult> pager = urbanFullReductionService.getPager(query, pagerInfo);
        return Result.success(pager);
    }

    @OperLog(operModul = "供应商-系统管理", operDesc = "添加满减规则设置")
    @SupplierLoginCheck(alias = "SystemManageOperationAlias")
    @PostMapping(value = "/urbanFullReduction/add")
    public Result<String> urbanFullReductionAdd(@RequestBody UrbanFullReductionResult req, HttpServletRequest request, HttpServletResponse response) {
        try {
            urbanFullReductionService.addOrUpdate(req);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());

        }
        return Result.success("SUCCESS");
    }

    @OperLog(operModul = "供应商-系统管理", operDesc = "修改满减规则设置")
    @PlatformLoginCheck(alias = "SystemManageOperationAlias")
    @PostMapping(value = "/urbanFullReduction/update")
    public Result<String> urbanFullReductionUpdate(@RequestBody UrbanFullReductionResult req, HttpServletRequest request, HttpServletResponse response) {
        try {
            urbanFullReductionService.addOrUpdate(req);
        } catch (BusinessException e) {
            e.printStackTrace();
            return Result.failed(e.getCode(), e.getMessage());

        }
        return Result.success("SUCCESS");
    }

    @OperLog(operModul = "供应商-系统管理", operDesc = "删除满减规则设置")
    @PlatformLoginCheck(alias = "SystemManageOperationAlias")
    @PostMapping(value = "/urbanFullReduction/delete")
    public Result<String> urbanFullReductionDelete(@RequestBody JSONObject req, HttpServletRequest request, HttpServletResponse response) {
        Integer id = req.getInteger("id");
        urbanFullReductionService.delete(id);
        return Result.success("SUCCESS");
    }

    @PlatformLoginCheck(alias = "PlatformGtRegionListListAlias")
    @PostMapping(value = "/gtRegion/list")
    public Result<Page<GtRegionResult>> skuPriceTrendMap(@RequestBody GtRegionQuery param, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(param.getPageSize(), param.getPageIndex());
        param.setIsMustCity("Y");
        param.setType(2);
        Page<GtRegionResult> pager = gtRegionService.getPager(param, pagerInfo);
        return Result.success(pager);
    }

    @PlatformLoginCheck(alias = "PlatformGtRegionListListAlias")
    @PostMapping(value = "/gtRegion/update")
    public Result<String> updateIsMustCity(@RequestBody GtRegionQuery param, HttpServletResponse response) throws BusinessException {
        GtRegionResult gtRegionResult = new GtRegionResult();
        BeanUtils.copyProperties(gtRegionResult, param);
        gtRegionService.updateIsMustCity(gtRegionResult);
        return Result.success("success");
    }


    @PlatformLoginCheck(alias = "PlatformGtRegionListListAlias")
    @PostMapping(value = "/gtRegion/updateIsDisable")
    public Result<String> update(@RequestBody GtRegionQuery param, HttpServletResponse response) throws BusinessException {
        GtRegionResult gtRegionResult = new GtRegionResult();
        BeanUtils.copyProperties(gtRegionResult, param);
        gtRegionService.addOrUpdate(gtRegionResult);
        return Result.success("success");
    }


    @OperLog(operModul = "平台-充值规则管理", operDesc = "查询充值规则列表")
    @PlatformLoginCheck
    @PostMapping(value = "/RechargeRule/list")
    public Result<Page<RechargeRuleResult>> platformRechargeRuleList(@RequestBody PlatformSystemDeployReq req, HttpServletRequest request, HttpServletResponse response) {
        PagerInfo pagerInfo = setDefaultPageInfo(req.getPageSize(), req.getPageIndex());
        Page<RechargeRuleResult> platformSystemDeployResultPage = rechargeRuleService.listAllRules(pagerInfo);
        return Result.success(platformSystemDeployResultPage);
    }

    @OperLog(operModul = "平台-充值规则添加", operDesc = "充值规则添加")
    @PlatformLoginCheck
    @PostMapping(value = "/RechargeRule/add")
    public Result<String> platformRechargeRuleAdd(@RequestBody RechargeQuery req, HttpServletRequest request, HttpServletResponse response) {
        req.setPlatformId(getSupplier().getPlatformId());
        try {
            rechargeRuleService.saveRechargeRule(req);
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }

    @OperLog(operModul = "平台-充值规则修改", operDesc = "充值规则修改")
    @PlatformLoginCheck
    @PostMapping(value = "/RechargeRule/update")
    public Result<String> platformRechargeRuleUpdate(@RequestBody RechargeQuery req, HttpServletRequest request, HttpServletResponse response) {
        req.setPlatformId(getSupplier().getPlatformId());
        try {
            rechargeRuleService.updateRechargeRule(req);
        } catch (BusinessException e) {
            return Result.failed(e.getCode(), e.getMessage());
        }
        return Result.success("success");
    }

    @OperLog(operModul = "平台-充值规则删除", operDesc = "充值规则删除")
    @PlatformLoginCheck
    @PostMapping(value = "/RechargeRule/delete")
    public Result<String> platformRechargeRuleDelete(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) {
        Integer id = json.getInteger("id");
        rechargeRuleService.deleteRechargeRule(id);
        return Result.success("success");
    }

}
